package oj;

public class LC233 {
    public int countDigitOne(int n) {
        long base=1,res=0;
        while(base<=n){
            long a=n/base/10;
            long cur=(n/base)%10;
            long b=n%base;
            if(cur>1){
                res+=(a+1)*base;
            }else if(cur==1){
                res+=a*base+b+1;
            }else{
                res+=a*base;
            }
            base*=10;
        }
        return (int)res;
    }
}
